#include <iostream>
#include <queue>
#include <vector>
using namespace std;

// Custom comparator using a struct
struct MyCompare
{
    bool operator()(int a, int b) const
    {
        return (a % 10) < (b % 10); // Compare based on the last digit
    }
};

// Regular comparison function
bool cmpFunc(int a, int b)
{
    return (a % 10) < (b % 10);
}

void fun_priority_queue()
{
    vector<int> nums = {23, 15, 8, 42, 67};

    // 1. Default max-heap
    priority_queue<int, vector<int>, less<int>> max_heap(nums.begin(), nums.end());
    cout << "std::less (max-heap): ";
    while (!max_heap.empty())
    {
        cout << max_heap.top() << " ";
        max_heap.pop();
    }
    cout << endl;

    // 2. Min-heap
    priority_queue<int, vector<int>, greater<int>> min_heap(nums.begin(), nums.end());
    cout << "std::greater (min-heap): ";
    while (!min_heap.empty())
    {
        cout << min_heap.top() << " ";
        min_heap.pop();
    }
    cout << endl;

    // 3. Custom comparator struct (by last digit)
    priority_queue<int, vector<int>, MyCompare> pq1(nums.begin(), nums.end());
    cout << "MyCompare (by last digit): ";
    while (!pq1.empty())
    {
        cout << pq1.top() << " ";
        pq1.pop();
    }
    cout << endl;

    // 4. Lambda comparator
    auto cmp = [](int a, int b)
    { return (a % 10) < (b % 10); };
    priority_queue<int, vector<int>, decltype(cmp)> pq2(cmp, nums);
    cout << "Lambda (by last digit): ";
    while (!pq2.empty())
    {
        cout << pq2.top() << " ";
        pq2.pop();
    }
    cout << endl;

    // 5. Regular function comparator
    priority_queue<int, vector<int>, bool (*)(int, int)> pq3(cmpFunc, nums);
    cout << "Function pointer (by last digit): ";
    while (!pq3.empty())
    {
        cout << pq3.top() << " ";
        pq3.pop();
    }
    cout << endl;
}

// int main() {
//     fun_priority_queue();
//     return 0;
// }
